package com.hy.video.monitor.config;

import com.sendgrid.SendGrid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: mrcos
 * @description
 * @author: 张三少
 * @create: 2022-04-26 18:21
 **/
@RequiredArgsConstructor
@Configuration
public class EmailConfig {

    private final AppProperties appProperties;

    // 有时候不用api的时候"appProperties.getEmailProvider().getApiKey()"会报错
    // 所以添加注解"@ConditionalOnProperty"，有api-key才执行@Bean
    @ConditionalOnProperty(prefix = "mooc.email-provider", name = "api-key")
    @Bean
    public SendGrid sendGrid() {
        return new SendGrid(appProperties.getEmailProvider().getApiKey());
    }
}
